package cn.codingfish.framework;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

import cn.nexd.task.core.AsyncTask;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AtomicInteger count = new AtomicInteger(1);
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute().cancel(true);
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute().cancel(true);
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();
        new MyAsyncTask("Hello  " + count.getAndIncrement()).execute();

        android.os.AsyncTask ll;
    }

    private static class MyAsyncTask extends AsyncTask {

        private String mName = "AsyncTask";

        public MyAsyncTask(String name) {
            super();
            mName = name;
        }


        @Override
        protected void onPostExecute(Object o) {
            super.onPostExecute(o);
//            try {
//                Thread.sleep(3 * 1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Log.d("MyAsyncTask ", o.toString() + " execute finish at " + df.format(new Date()));
        }

        @Override
        protected Object doInBackground(Object[] params) {
//            try {
//                Thread.sleep(1000 * 3);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            return mName;

        }
    }
}
